package com.laolang.shop.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laolang.shop.common.core.util.CommonUtil;
import com.laolang.shop.modules.sys.entity.SysRole;
import com.laolang.shop.modules.sys.entity.SysUserRole;
import com.laolang.shop.modules.sys.mapper.SysRoleMapper;
import com.laolang.shop.modules.sys.mapper.SysUserRoleMapper;
import com.laolang.shop.modules.sys.service.SysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author khlbat
 * @version 1.0
 * @date 2020/11/1 20:46
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements SysUserRoleService {

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public List<SysRole> listByUserId(Long userId) {
        List<SysRole> roles = null;
        if (CommonUtil.isAdmin(userId)) {
            roles = sysRoleMapper.selectList(Wrappers.lambdaQuery());
        } else {
            roles = sysUserRoleMapper.listByUserId(userId);
        }
        return roles;
    }
}
